<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>课程列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }
        form {
            margin-bottom: 20px;
            display: flex;
            gap: 10px;
        }
        input[type="text"] {
            padding: 8px;
            width: 200px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        input[type="submit"] {
            padding: 8px 16px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #45a049;
        }
        a {
            text-decoration: none;
            color: #007BFF;
            margin-left: 10px;
        }
        a:hover {
            text-decoration: underline;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            font-size: 16px;
            min-width: 400px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
            border: none;
        }
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f4f4f4;
            color: #333;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        tr:hover {
            background-color: #f1f1f1;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            width: 100%;
        }
        p.message {
            margin-top: 20px;
            font-size: 16px;
            color: #d9534f;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>课程列表</h1>
    <form action="getCourse">
        <input type="text" name="name" placeholder="请输入课程名">
        <input type="submit" value="查询">
    </form>
    <a href="addCourse.jsp">添加课程</a>
    <table>
        <thead>
        <tr>
            <th>课程名</th>
            <th>课程人数</th>
            <th>开始时间</th>
            <th>结束时间</th>
            <th>教师</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${courseList}" var="course">
            <tr>
                <td>${course.name}</td>
                <td>${course.count}</td>
                <td>${course.startDate}</td>
                <td>${course.endDate}</td>
                <td>${course.teacher}</td>
                <td>
                    <a href="javascript:deleteCourseById(${course.id})">删除</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <p class="message">${msg}</p>
</div>
<script>
    function deleteCourseById(id) {
        if (confirm("确定删除吗？")) {
            location.href = "deleteCourseById?id=" + id;
        }
    }
</script>
</body>
</html>
